package com.zjw.config;

import java.io.*;
import java.util.Properties;

/**
 * @package: config
 * @className: ConfigManager
 * @author: 翟
 * @date: 2025/3/31 1:49
 */

public class ConfigManager {
    private static Properties properties = null;
    private static final String DATABASE_CONFIG_FILE_NAME = "databaseConfig.properties";

    static {
        //IO流读取数据库配置文件信息
        InputStream inputStream = ConfigManager.class.getClassLoader().getResourceAsStream(DATABASE_CONFIG_FILE_NAME);
        if (inputStream == null)
            throw new RuntimeException("数据库配置文件没有找到！！！");
        else
            properties = new Properties();
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("数据库配置文件配置有误！！！");
        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static String getProperty(String key) {
        return properties.getProperty(key);
    }
}
